<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*,java.util.*"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>



<%
    Connection conn = null;
    Statement stmt = null;

    String StudentID = (String)session.getAttribute("StudentID");
	String courseID = request.getParameter("courseid");
	String type = request.getParameter("type");	
	String record = "";
	char num = type.charAt(0);
	switch(num){
		case '0':
			record = "加油" + request.getParameter("record");
			break;
		case '1':
			record = "關心" + request.getParameter("record");
			break;
		case '2':	
			record = "祝福" + request.getParameter("record");
			break;
	}	
	
	String MasterID = "";
    
    try {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection("jdbc:mysql://140.119.19.171/klp","case", "12345");
      stmt = conn.createStatement();
	  String sql1 = "SELECT e.Stu_Id , c.C_Name , m.angel_Id , e.Pair_No FROM klp.course c , klp.elective e , klp.pair p , klp.master m where e.Pair_No = p.Pair_No AND e.C_No = c.C_No AND p.Pair_No = m.Pair_No AND e.Stu_Id = '" + StudentID + "' AND e.C_No = '" + courseID + "' AND p.Type = 'Master'";
      ResultSet rs = stmt.executeQuery(sql1);    
	  
      int n;
      //rs.first();
	   if (rs.next()){
           Statement stmtNew = conn.createStatement();
           String upd = 
               "INSERT INTO talk(Pair_No,DateTime,Record ) values ('"+rs.getString("Pair_No")+"', NOW() ,'" + record + "')";
           n=stmtNew.executeUpdate(upd);
        }
        rs.close();
    }
    catch(SQLException e) {

    }
    finally {
        try {
            stmt.close();
            conn.close();
        }
        catch(SQLException e) {

        }
    }
 %>

OK!!!

<% response.setHeader("Refresh", "1; URL=index.jsp"); %>
</body>
</html>